<template>
	<div class="system-role-container layout-padding">
		<div class="system-role-padding layout-padding-auto">
			<el-card shadow="hover" class="pageQueryBoxArea mb10">
				<el-form :model="state.param" :inline="true">
					<el-form-item label="门店类型：">
						<el-select v-model="state.param.source" placeholder="请选择门店类型">
							<el-option v-for="item in state.query.storeType" :key="item.value"
								:label="item.label" :value="item.value" />
						</el-select>
					</el-form-item>
					<el-form-item label="门店状态：">
						<el-select v-model="state.param.storeStatus" placeholder="请选择门店状态">
							<el-option v-for="item in state.query.storeStatus" :key="item.value"
								:label="item.label" :value="item.value" />
						</el-select>
					</el-form-item>
				
					<el-form-item label="选择门店：">
						<el-select v-model="state.param.nodeId" placeholder="请选择门店">
							<el-option v-for="item in state.query.storeList" :key="item.id"
								:label="item.name" :value="item.id" />
						</el-select>
					</el-form-item>
					<el-form-item label="截止日期：">
						<el-date-picker v-model="state.param.dateTime"
							type="date" placeholder="请选择截止日期" />
					</el-form-item>
					<el-form-item label="负债类型：">
						<el-select v-model="state.param.liabilitiesType" placeholder="请选择卡项类型">
							<el-option v-for="item in state.query.liabilitiesType" :key="item.value" :label="item.label"
								:value="item.value" />
						</el-select>
					</el-form-item>
					<el-form-item label="会员搜索：">
						<el-input v-model="state.param.keyword" placeholder="请输入会员搜索" clearable></el-input>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="search()">
							<el-icon>
								<ele-Search />
							</el-icon> 搜 索
						</el-button>
						<el-button type="primary" @click="search()">
							<el-icon>
								<ele-Refresh />
							</el-icon> 重 置
						</el-button>
					</el-form-item>
				</el-form>
			</el-card>
			<el-card shadow="hover" v-loading="state.loading" style="display: flex;flex-direction: column;flex: 1;height: inherit;">
				<section style="flex: 1;display: flex;flex-direction: column; flex: 1;height: inherit;">
					<el-table :data="state.tableData" v-loading="state.loading" v-if="state.param.liabilitiesType === 1">
						<el-table-column label="ID" prop="name" width="90" />
						<el-table-column label="门店" prop="name" />
						<el-table-column label="类型" prop="name" />
						<el-table-column label="状态" prop="revenueTotal" />
						<el-table-column label="总计营收" prop="debtTotal" />
						<el-table-column label="总计负债" prop="debtTotal"  />
						<el-table-column label="负债率" prop="debtTotal"  />
						<el-table-column label="操作">
							<template #default="scope">
								<el-button text type="primary" @click="previewInfo(scope.row.id)">
									详情
								</el-button>
							</template>
						</el-table-column>
						<template #empty>
							<el-empty description="暂无数据" />
						</template>
					</el-table>

					<el-table :data="state.tableData" v-loading="state.loading" v-if="state.param.liabilitiesType === 2">
						<el-table-column label="ID"  prop="id" width="90" />
						<el-table-column label="名称"  prop="id" />
						<el-table-column label="属性"  prop="cardId" />
						<el-table-column label="规格"  prop="photo" />
						<el-table-column label="零售价"  prop="cardName" />
						<el-table-column label="实售价"  prop="property" />
						<el-table-column label="剩余次数/时间" prop="spec"  />
						<el-table-column label="负债金额" prop="cellPrice"  />
						<el-table-column label="总计成本" prop="useCount"  />
						<el-table-column label="产品成本" prop="useTime"  />
						<el-table-column label="手工成功" prop="debtMoney" />
						<el-table-column label="绩效成本" prop="totalCost" />
						<el-table-column label="操作">
							<template #default="scope">
								<el-button text type="primary" @click="previewInfo(scope.row.id)">
									详情
								</el-button>
							</template>
						</el-table-column>
						<template #empty>
							<el-empty description="暂无数据" />
						</template>
					</el-table>
					
					<el-table :data="state.tableData" v-loading="state.loading" v-if="state.param.liabilitiesType === 3">
						<el-table-column label="ID"  prop="id" width="90" />
						<el-table-column label="名称"  prop="id" />
						<el-table-column label="属性"  prop="cardId" />
						<el-table-column label="规格"  prop="photo" />
						<el-table-column label="零售价"  prop="cardName" />
						<el-table-column label="实售价"  prop="property" />
						<el-table-column label="剩余次数/时间" prop="spec"  />
						<el-table-column label="负债金额" prop="cellPrice"  />
						<el-table-column label="总计成本" prop="useCount"  />
						<el-table-column label="产品成本" prop="useTime"  />
						<el-table-column label="手工成功" prop="debtMoney" />
						<el-table-column label="绩效成本" prop="totalCost" />
						<el-table-column label="操作">
							<template #default="scope">
								<el-button text type="primary" @click="previewInfo(scope.row.id)">
									详情
								</el-button>
							</template>
						</el-table-column>
						<template #empty>
							<el-empty description="暂无数据" />
						</template>
					</el-table>

					<el-table :data="state.tableData" v-loading="state.loading" v-if="state.param.liabilitiesType === 4">
						<el-table-column label="ID"  prop="id" width="90" />
						<el-table-column label="名称"  prop="id" />
						<el-table-column label="属性"  prop="cardId" />
						<el-table-column label="规格"  prop="photo" />
						<el-table-column label="零售价"  prop="cardName" />
						<el-table-column label="实售价"  prop="property" />
						<el-table-column label="剩余次数/时间" prop="spec"  />
						<el-table-column label="负债金额" prop="cellPrice"  />
						<el-table-column label="总计成本" prop="useCount"  />
						<el-table-column label="产品成本" prop="useTime"  />
						<el-table-column label="手工成功" prop="debtMoney" />
						<el-table-column label="绩效成本" prop="totalCost" />
						<el-table-column label="操作">
							<template #default="scope">
								<el-button text type="primary" @click="previewInfo(scope.row.id)">
									详情
								</el-button>
							</template>
						</el-table-column>
						<template #empty>
							<el-empty description="暂无数据" />
						</template>
					</el-table>

					<el-table :data="state.tableData" v-loading="state.loading" v-if="state.param.liabilitiesType === 5">
						<el-table-column label="ID"  prop="id" width="90" />
						<el-table-column label="名称"  prop="id" />
						<el-table-column label="属性"  prop="cardId" />
						<el-table-column label="规格"  prop="photo" />
						<el-table-column label="零售价"  prop="cardName" />
						<el-table-column label="实售价"  prop="property" />
						<el-table-column label="剩余次数/时间" prop="spec"  />
						<el-table-column label="负债金额" prop="cellPrice"  />
						<el-table-column label="总计成本" prop="useCount"  />
						<el-table-column label="产品成本" prop="useTime"  />
						<el-table-column label="手工成功" prop="debtMoney" />
						<el-table-column label="绩效成本" prop="totalCost" />
						<el-table-column label="操作">
							<template #default="scope">
								<el-button text type="primary" @click="previewInfo(scope.row.id)">
									详情
								</el-button>
							</template>
						</el-table-column>
						<template #empty>
							<el-empty description="暂无数据" />
						</template>
					</el-table>

					<el-table :data="state.tableData" v-loading="state.loading" v-if="state.param.liabilitiesType === 6">
						<el-table-column label="ID"  prop="id" width="90" />
						<el-table-column label="名称"  prop="id" />
						<el-table-column label="属性"  prop="cardId" />
						<el-table-column label="规格"  prop="photo" />
						<el-table-column label="零售价"  prop="cardName" />
						<el-table-column label="实售价"  prop="property" />
						<el-table-column label="剩余次数/时间" prop="spec"  />
						<el-table-column label="负债金额" prop="cellPrice"  />
						<el-table-column label="总计成本" prop="useCount"  />
						<el-table-column label="产品成本" prop="useTime"  />
						<el-table-column label="手工成功" prop="debtMoney" />
						<el-table-column label="绩效成本" prop="totalCost" />
						<el-table-column label="操作">
							<template #default="scope">
								<el-button text type="primary" @click="previewInfo(scope.row.id)">
									详情
								</el-button>
							</template>
						</el-table-column>
						<template #empty>
							<el-empty description="暂无数据" />
						</template>
					</el-table>
					<el-row justify="end">
						<el-col :span="24" class="flex-end-center">
							<el-pagination @size-change="onHandleSizeChange" @current-change="onHandleCurrentChange"
								class="mt15" :pager-count="5" :page-sizes="[10, 20, 30,50,100,500,1000]"
								v-model:current-page="state.param.pageNum" background v-model:page-size="state.param.pageSize"
								layout="total, sizes, prev, pager, next, jumper" :total="state.total">
							</el-pagination>
						</el-col>
					</el-row>
				</section>
			</el-card>
		</div>
		<CardDialog v-model="cardDialogVisble" :statistics="state.param.liabilitiesType" :id="state.param.storeId" :title="liabilitiesTypeName" />
	</div>
</template>

<script setup lang="ts" name="funCountup">
import {  onMounted, reactive, ref, computed } from 'vue';

import CardDialog from '/@/views/analysis/liabilities/components/CardDialog.vue' 
import type { storeNodeListData, channelListData } from "/@/types/order";
import { storeNodeList } from '/@/api/order';
type TliabilitiesType = 1 | 2 | 3 | 4 | 5 ;
const state = reactive({
	param: {
		type: 4,
		source: 0, // 0 门店 2 线上 //设置不了得值是哪个？ 
		storeStatus:-1, 
		status: null,
		nodeId:-1,
		// 支付方式
		dateTime: [], 
		total: 0,
		keyword: "",
		pageNum: 1,
		pageSize: 10, 
		storeType: null as null | number,
		statistics: 1, 
		liabilitiesType: 1 as TliabilitiesType,
		storeId: 0
	},
	query: {
		orderSource: [
			{ value: 0, label: '门店订单' },
		],
		storeType: [
			{ value: null, label: '全部' },
			{ value: 0, label: '直营' },
			{ value: 1, label: '加盟' }
		],
		storeStatus:[
			{ value: -1, label: '全部' },
			{ value: 1, label: '正常' },
			{ value: 2, label: '闭店' },
			{ value: 3, label: '休息' }
		],
		liabilitiesType: [
			{ value: 1, label: '总计负债' },
			{ value: 2, label: '卡项负债' },
			{ value: 3, label: '储值卡负债' },
			{ value: 4, label: '充值负债' },
			{ value: 5, label: '会员负债' },
		],
		cardType: [
			{ value: null, label: '全部' },
			{ value: 0, label: '疗程卡' },
			{ value: 1, label: '单次卡' },
			{ value: 2, label: '体验卡' },
		],
		storeList: [] as Array<storeNodeListData>,
		orderStatus: [
			{ value: null, label: '全部' },
			{ value: 4, label: '已服务' },
			{ value: 14, label: '已撤销' },
		],
		saleChannel: [] as Array<channelListData>,
		orderType:[
			{ value: 999, label: '全部订单' },
			{ value: 1, label: '换卡服务' },
			{ value: 2, label: '余卡服务' },
		]
	},
	loading: false,
	total: 0,
	tableData: [
		{
			id: 1,
			cardItemName: '测试',
			property: '属性名称',
			spec: '规格',
			salesVolume: '销量',
			cellPrice: '销售价格',
			cellRatio: '销售占比',
			notUsedPrice: '未消耗金额',
			notUsedRatio: '未消耗占比',
			popularizePeple: '普及人数',
			popularizeRatio: '普及率',
			holdPeple: '持有人数',
			holdRatio: '持有率',
			lossPeple: '流失人数',
			lossRatio: '流失率',
			serviceCount: '服务量',
			consume: '消耗业绩',
			averageMonth: '月平均',
			averagePeple: '人平均',
			price: '客单价',
			repurchaseCycle: '复购周期',
			serviceGoodRatio: '服务好评率',
			sexRatio: '男女比例',
			age: '年龄'
		}
	] as Array<any>
		
});

const liabilitiesTypeName= computed(() => {
	let arr = state.query.liabilitiesType.filter(item => item.value === state.param.liabilitiesType)
	return arr.length ? arr[0].label : '-'
})

const shortcuts = [
	{
		text: '本月',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.setDate(1))
		return [start, end]
		},
	},
	{
		text: '近一个月',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
		return [start, end]
		},
	},
	{
		text: '近三个月',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
		return [start, end]
		},
	},
	{
		text: '近半年',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.getTime() - 3600 * 1000 * 24 * 180)
		return [start, end]
		},
	},
	{
		text: '近一年',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.getTime() - 3600 * 1000 * 24 * 365)
		return [start, end]
		},
	},
]

const cardDialogVisble = ref(false)
const defaultTime2: [Date, Date] = [
  new Date(2000, 1, 1, 12, 0, 0),
  new Date(2000, 2, 1, 8, 0, 0),
]

const search = () => {}

const onHandleSizeChange = () => {}
const onHandleCurrentChange = () => {}
const previewInfo = (id: number) => {
	state.param.storeId = id
	cardDialogVisble.value = true
}
/**
 * 获取门店列表
 * mode  null /全部   0直营  1加盟
 */
 const getStoreNodeList = async () => {
	const { results } = await storeNodeList({ mode: null, current: 1, size: 50 });
	let no1 = [{id:null,name:'全部'}]
	state.query.storeList = [...no1, ...results.records];
}


// 页面加载时
onMounted(() => {
	getStoreNodeList()
});

</script>

<style scoped lang="scss">
:deep(.el-card__body){
	display: flex;
	flex-direction: column;
	flex: 1;
	height: inherit;
	.el-table{
		flex: 1;
		.el-table__inner-wrapper::before{
			background: none !important;
		}
	}
}

</style>
